package com.example.leetcode.tree;

/**
 * 平衡二叉树
 */
public class Tree3 {

    public static void main(String[] args) {

    }


    public boolean IsBalanced_Solution(TreeNode pRoot) {

        deep(pRoot);

        return isBalanced;
    }


    boolean isBalanced = true;

    public int deep(TreeNode treeNode) {
        if (treeNode == null) {
            return 0;
        }

        int left = deep(treeNode.left);
        int right = deep(treeNode.right);

        if (Math.abs(left -right) > 1) {
            isBalanced =false;
        }

        return Math.max(left , right) +1;
    }

}
